package com.itheima.controller;


import com.itheima.pojo.PageBean;
import com.itheima.pojo.R;
import com.itheima.pojo.Checkltem;
import com.itheima.service.CheckltemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/checkitem")
public class CheckltemController {
    @Autowired
    private CheckltemService checkltemService;

    @PostMapping("/findPage")
    public Map<String,Object> findPage(@RequestBody PageBean pageBean){
        return checkltemService.findPage(pageBean);
    }

    @PostMapping("/add")
    public R add(@RequestBody Checkltem checkltem){
        boolean flag = checkltemService.add(checkltem);
        return new R(null,flag,"新增检查项成功");
    }
    @GetMapping("/delete")//删除操作
    public R delete(Integer id){
        boolean flag = checkltemService.delete(id);
        return new R(null,flag,"删除检查项成功");
    }

    @GetMapping("/findById")
    public R getById(Integer id){
        Checkltem checkltem = checkltemService.getById(id);
        boolean flag = checkltem != null ? true: false;
        String msg = flag != true ? "" : "查询检查项成功!";
        return new R(checkltem,flag,msg);
    }

    @PostMapping("/edit")//修改操作
    public R  update(@RequestBody Checkltem checkltem){
        boolean flag = checkltemService.update(checkltem);
        return new R(null,flag,"修改检查项成功");
    }
}
